package com.ai.module.suno.controller;

import com.ai.module.chat.common.ano.NoAuth;
import com.ai.module.chat.common.domain.BasePage;
import com.ai.module.suno.domain.bo.SunoInfoTask;
import com.ai.module.suno.domain.req.SunoReq;
import com.ai.module.suno.domain.vo.SunoGenerateVo;
import com.ai.module.suno.domain.vo.SunoRecordVo;
import com.ai.module.suno.domain.vo.UserSunoVo;
import com.ai.module.suno.service.SunoService;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: heJinQin
 * @create: 2024-04-24 20:10
 * @description:
 **/
@Slf4j
@RestController
@RequestMapping("/member/test/suno")
public class SunoAiController {

    @Autowired
    private SunoService sunoService;

    @GetMapping("/file/download/{fileName}")
    @NoAuth
    public void downFileById(@PathVariable String fileName, HttpServletResponse response) throws IOException {
        sunoService.download(fileName, response);
    }

    /**
     * 通用生成 suno 歌曲
     * @param sunoGenerate
     * @return
     */
    @PostMapping("/generate")
    @NoAuth
    public JSONObject generate(@RequestBody SunoGenerateVo sunoGenerate) {
        return sunoService.generate(sunoGenerate);
    }

    /**
     * 查询suno任务
     * @param id
     * @return
     */
    @GetMapping("/fetch/{id}")
    @NoAuth
    public SunoInfoTask fetch(@PathVariable String id) {
        return sunoService.fetch(id);
    }

    /**
     * 查询 用户生成的 suno歌曲记录
     * @param page
     * @return
     */
    @PostMapping("/sunoRecord")
    @NoAuth
    public IPage<UserSunoVo> sunoRecord(@RequestBody SunoReq page) {
        return sunoService.sunoRecord(page);
    }

    /**
     * 查询 用户生成的 suno歌曲记录详情
     * @param sunoId
     * @return
     */
    @GetMapping("/sunoDetail")
    @NoAuth
    public SunoRecordVo sunoDetail(String sunoId) {
        return sunoService.sunoDetail(sunoId);
    }



}
